#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: update_01_20210508.py
# @time: 2021/5/8 10:08
# @desc:
from .utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from .views.configs import SCENE_COLLECTION

scene = retrieve_all_mongo_values(
    {},
    collection_name=SCENE_COLLECTION,
)

for i in scene:
    if i["historyClamp"] is None:
        i["historyClamp"] = []
    elif "historyClamp" in i.keys():
        i["historyClamp"] = list(set(i["historyClamp"]))
    else:
        i["historyClamp"] = []

    if i["standardClamp"] is None:
        i["standardClamp"] = []
    elif "standardClamp" in i.keys():
        i["standardClamp"] = list(set(i["standardClamp"]))
    else:
        i["standardClamp"] = []

    update_mongo_value(
        filter_condition={"number": i["number"]},
        new_value={"$set": i},
        collection_name=SCENE_COLLECTION,
    )
